//----------------------------------------------------------------------------
// Global vars
//----------------------------------------------------------------------------

//lettertypes
var customFont  = 'HelveticaNeue-Bold';
var customFont2 = 'Harabara';

//Kleuren
var donkerblauw  = '#244172';
var borderblauw  = '#2776BG';
var schaduwgroen = '#CDDBAD';
var midgroen     = '#78B450';
var donkergroen  = '#587E37';
var bordergroen  = '#37641E';
var wit          = '#FFFFFF';
var zwart        = '#000000';

//UI elementen
var messageView = Titanium.UI.createView({
   id: 'messageview',
   height: 40,
   width: 250,
   borderRadius: 10,
   backgroundColor: zwart,
   opacity: 0.7,
   touchEnabled:false
});
if (isIphone()) {
   messageView.setBottom(30);
}
else if (isIpad()) {
   messageView.setBottom(70);
}

var messageLabel = Titanium.UI.createLabel({
   id:'messagelabel',
   text: '',
   color: wit,
   width: 250,
   height:'auto',
   font:{
      fontFamily:'Helvetica Neue',
      fontSize:13
   },
   textAlign:'center'
});


//----------------------------------------------------------------------------
// Functions
//----------------------------------------------------------------------------
function isIpad() {
   if (Ti.Platform.osname === "ipad") {
      return true;
   } else {
      return false;
   }
}

function isIphone() {
   if (Ti.Platform.osname === "iphone") {
      return true;
   } else {
      return false;
   }
}

function isAndroid() {
   if (Ti.Platform.osname === "android") {
      return true;
   } else {
      return false;
   }
}

function getCurrentLocation() {
   /* returned JSON object should look like this:
    {
    "accuracy": 100,
    "altitude": 0,
    "altitudeAccuracy": null,
    "heading": 0,
    "latitude": 40.493781233333333,
    "longitude": -80.056671
    "speed": 0,
    "timestamp": 1318426498331
    }
    */
   if (!Ti.Geolocation.locationServicesEnabled) {
      alert('Activeer aub locatie voorzieningen');
      return null;
   }

   //IOS only
   Titanium.Geolocation.purpose = 'Huidige positie bepalen';
   Titanium.Geolocation.getCurrentPosition(function(e) {
      if (e.error) {
         Ti.API.error('Fout: ' + e.error);
         return null;
      }
      Ti.API.info('Locatie: ' + e.coords);
      return e.coords;
   });

}

function getDate() {
   var currentTime = new Date();
   var hours = currentTime.getHours();
   var minutes = currentTime.getMinutes();
   var seconds = currentTime.getSeconds();
   var month = currentTime.getMonth() + 1;
   var day = currentTime.getDate();
   var year = currentTime.getFullYear();

   if (hours < 10) {
      hours = "0" + hours
   };
   if (minutes < 10) {
      minutes = "0" + minutes
   };
   if (seconds < 10) {
      seconds = "0" + seconds
   };

   return month + "-" + day + "-" + year + "-" + hours + ":" + minutes + ":" + seconds;
}

function log(msg) {
   Ti.API.info(getDate() + " - " + msg);
}

